<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3、this指向之call、apply、bind</title>
</head>
<body>
    <button>按钮</button>
    <button>按钮</button>
    <button>按钮</button>
    <script>
        /**
         * this
         * 普通函数调用 => window
         * 构造函数调用 => 实例对象
         * 对象方法调用 => 该方法所属对象
         * 事件绑定方法 => 绑定事件对象
         * 定时器函数 => window
         * 立即执行函数 => window
         * **/

        // call
        function Father(name, age){
            this.name = name;
            this.age = age;
        }

        function Son(name, age){
            Father.call(this, name, age);
        }

        var son = new Son('刘德华', 12);
        console.log(son);
        console.log('-----分割线-----');

        // apply
        var arr = [9, 2, 4, 1];
        var max = Math.max.apply(null, arr);
        var min = Math.min.apply(null, arr);
        console.log(max ,min);
        console.log('-----分割线-----');

        // bind
        var btns = document.querySelectorAll('button');
        btns.forEach(function(value, index){
            value.onclick = function(){
                this.disabled = true;
                setTimeout(function(){
                    this.disabled = false;
                }.bind(this), 2000);
            }
        })
    </script>
</body>
</html>